{% extends 'template.html' %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="alert alert-danger alert-dismissable" style="display: none;" id="refresh_notice">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <span id="refresh_notice_text"></span>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">提交刷新</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="form-group row">
                            <label class="col-sm-12">选择游戏项目</label>
                            <div class="col-sm-4">
                                <select class="form-control" id="project" name="project">
                                    <option value="0"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-12">根据Url刷新</label>
                            <div class="col-sm-6">
                                    <textarea rows="8" name="cdn_url" id="cdn_url" class="form-control"
                                              placeholder="请填写url，多个url分多行填写"></textarea>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-sm-12 form-group">
                                <button class="btn btn-primary" id="commit_url">提交</button>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-12">根据目录刷新</label>
                            <div class="col-sm-6">
                                    <textarea rows="8" name="cdn_dir" id="cdn_dir" class="form-control"
                                              placeholder="请填写cdn目录，多个目录分多行填写"></textarea>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-sm-12 form-group">
                                <button class="btn btn-primary" id="commit_dir">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Modal-->
            <div class="modal fade" id="Modal-detail" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">提交url或目录详情</h4>
                        </div>
                        <form>
                            <div class="modal-body">
                                <textarea class="form-control" style="width: 100%;" rows="20" readonly="true"
                                          id="refresh_obj_detail"></textarea>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <!--<button type="submit" class="btn btn-primary" name='action'>保存</button>-->
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">刷新记录
                    <small>（只保留最近30天数据）</small>
                </h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        {% if cdn_refresh_record %}

                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>提交时间</th>
                                    <th>提交人</th>
                                    <th>刷新url/dir</th>
                                    <th>任务id</th>
                                    <th>刷新状态</th>
                                    <th>查询刷新结果</th>
                                    <th>失败原因</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for record in cdn_refresh_record %}
                                    <tr>
                                        <td>{{ record.commit_time|date:"Y-m-d H:i:s" }}</td>
                                        <td>{{ record.commit_user.username }}</td>
                                        <td>
                                            <button class="btn btn-sm btn-primary"
                                                    onclick="view_refresh_detail({{ record.id }})">查看详情
                                            </button>
                                        </td>
                                        <td>
                                            {% if record.task_id %}{{ record.task_id }}{% endif %}
                                        </td>
                                        <td>
                                            {% if record.result == -1 %}
                                                <button class="btn btn-sm btn-danger">{{ record.get_result_display }}</button>
                                            {% elif record.result == 0 %}
                                                <button class="btn btn-sm btn-info">{{ record.get_result_display }}</button>
                                            {% elif record.result == 2 %}
                                                <button class="btn btn-sm btn-warning">{{ record.get_result_display }}</button>
                                            {% else %}
                                                <button class="btn btn-sm btn-success">{{ record.get_result_display }}</button>
                                            {% endif %}
                                        </td>
                                        <td>
                                            {% if record.result == -1 or record.result == 0 %}
                                                <button class="btn btn-sm btn-primary"
                                                        onclick="manual_refresh({{ record.id }})">查询
                                                </button>
                                            {% endif %}
                                        </td>
                                        <td>
                                            {% if record.result == -1 %}{{ record.remark }}{% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>

                        {% else %}
                            <p>你还没有提交过刷新！</p>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

    </div>
{% endblock %}
{% block bodyjs %}
    <script src="/static/js/jquery.dataTables.js"></script>
    <script src="/static/js/cdn_refresh.js?v=20190628001"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
    <!-- showloading.js-->
    <script src="/static/js/showloading.min.js"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
    <!-- showloading.css-->
    <link href="/static/css/showloading.css" rel="stylesheet" media="screen">
    <link href="/static/css/select2-bootstrap.css" rel="stylesheet" type="text/css">
{% endblock %}
